{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/idealo/image-super-resolution/blob/master/notebooks/ISR_Assistant.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "3-5SSq3HHq1X"
   },
   "source": [
    "# ISR Assistant"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "-gBSn6zkIShy"
   },
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "jZa8x-o6IL9C"
   },
   "source": [
    "Install the package, download the sample weights, a sample image and a sample configuration file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "bO7XnZFW72B9"
   },
   "outputs": [],
   "source": [
    "!pip install ISR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "90lQCy9W8Jc9"
   },
   "outputs": [],
   "source": [
    "!wget https://github.com/idealo/image-super-resolution/raw/master/weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5\n",
    "!wget https://github.com/idealo/image-super-resolution/raw/master/weights/sample_weights/rdn-C6-D20-G64-G064-x2/PSNR-driven/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5\n",
    "!wget https://github.com/idealo/image-super-resolution/raw/master/weights/sample_weights/rdn-C3-D10-G64-G064-x2/PSNR-driven/rdn-C3-D10-G64-G064-x2_PSNR_epoch134.hdf5\n",
    "!mkdir weights\n",
    "!mv *.hdf5 weights\n",
    "!wget http://images.math.cnrs.fr/IMG/png/section8-image.png\n",
    "!mkdir -p data/input/sample\n",
    "!mv *.png data/input/sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "ZwgxdKUU8zdU"
   },
   "outputs": [],
   "source": [
    "!wget https://github.com/idealo/image-super-resolution/raw/master/config.yml"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "ARE4tIJjIBO6"
   },
   "source": [
    "## Use the assistant for prediction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "xi0cr_ssIKQx"
   },
   "source": [
    "The assistant will guide you through either training or prediction, letting you iteratively customize almost every aspect of the configuration file. In this example we will perform prediction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 581.0
    },
    "colab_type": "code",
    "id": "o_YR1DvV79sF",
    "outputId": "8c545e59-55cb-441b-8f02-e7a20564cc46"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(t)raining or (p)rediction? (t/p) p\n",
      "Default options for everything? (y/[n]) n\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Select SR (generator) network\n",
      "0: rrdn\n",
      "1: rdn\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "Load pretrained weights for rdn? ([y]/n/d) y\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "0: rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5 \n",
      "\n",
      "1: rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5 \n",
      "\n",
      "2: rdn-C3-D10-G64-G064-x2_PSNR_epoch134.hdf5 \n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>> Select folder or weights for rdn\n",
      "1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "rdn parameters:\n",
      "{'C': 6, 'D': 20, 'G': 64, 'G0': 64, 'x': 2}\n",
      "Select test set\n",
      "0: sample\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Loaded weights from \n",
      " > ./weights/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5\n",
      "Results in:\n",
      " > ./data/output/sample/rdn-C6-D20-G64-G064-x2/div2k-e086\n",
      "Processing file\n",
      " > ./data/input/sample/section8-image.png\n",
      "Elapsed time: 4.124618768692017s\n",
      "Result in: ./data/output/sample/rdn-C6-D20-G64-G064-x2/div2k-e086/section8-image.png\n"
     ]
    }
   ],
   "source": [
    "from ISR import assistant\n",
    "assistant.run(config_file='config.yml')"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "name": "ISR assistant.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
